<? 
include("includes/functions.php");

// Retrieve provider details
$sql = "SELECT * from oa_btb_Providers
		WHERE
			Provider_PID = '$PID'";
$result = mysql_db_query($dbname,$sql);
$row1 = mysql_fetch_assoc($result);

$pName    = stripslashes($row1[ProviderNameFull]);
$pClass  = $row1[ProviderClass];
$pServiceArea = $row1[ProviderServiceArea];
$pDesc    = stripslashes($row1[ProviderDesc]);
$pMission = stripslashes($row1[ProviderMission]);
$pURL     = $row1[ProviderWebURL];
$pViews   = $row1[Views];

$sql = "SELECT * from oa_btb_Sites
		WHERE
			Provider_ID = '$PID'";
$result = mysql_db_query($dbname,$sql);

// Determine class icons
switch ($pClass) {
    case "for-profit":
    $pIcon = "icon_fp.gif";
    $pAlt  = "For Profit";
    break;
    case "non-profit":
    $pIcon = "icon_np.gif";
    $pAlt  = "Non-Profit";
    break;
    default:
	$pIcon = "spacer.gif";
	$pAlt = "";
}
// Determine service area icons
switch ($pServiceArea) {
    case "federal":
    $sIcon = "icon_natl.gif";
    $sAlt  = "National/Federal";
    break;
    case "state":
    $sIcon = "icon_or.gif";
    $sAlt  = "State";
    break;
    default:
	$sIcon = "spacer.gif";
	$sAlt = "";
}

// Retrieve other services/products
$sqlS = "SELECT * from oa_btb_Products WHERE Provider_ID = '$PID'";
$resultS = mysql_db_query($dbname,$sqlS);
$rowsS = mysql_num_rows($resultS);

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html>
<head>
	<title><?=$pName; ?></title>
	<link rel="STYLESHEET" href="styles/layout.css">
</head>

<body onLoad="print();">
<div id="printBody">
<table border="0" width="100%">
<tr>
	<td width="80%"><h1><?=$pName; ?></h1></td>
	<td align="right"><a href="#" onClick="print();"><b>Send to Printer</b></a></td>
</tr>
</table>
		<table class="datatable" summary="A List of Current Service Providers">
		<tr>
			<th scope="col" width=50%>Location</th>
			<th scope="col" width=50%>Contacts</th>
		</tr>
		<?
		while ($value = mysql_fetch_assoc($result)) {
			echo "<tr>\n";
									
			$sSiteName = stripslashes($value[SiteName]);
			$sStreet1  = $value[SiteStreet1];
			$sStreet2  = $value[SiteStreet2];
			$sCity     = $value[SiteCity];
			$sCounty   = $value[SiteCounty];
			$sState    = $value[SiteStateAbbr];
			$sZip      = $value[SiteZipCode];
			$sPhone1   = $value[SitePhoneMain];
			$sPhone2   = $value[SitePhoneFree];
			$sPhone3   = $value[SitePhoneFax];
			$sPhone4   = $value[SitePhoneTTY];
			$sEmail    = $value[SiteEmailGeneral];
			$sContact1 = $value[SiteContact1_ID];
			$sContact2 = $value[SiteContact2_ID];
			$sAccess   = $value[SiteAccessibility];
			$sHours    = $value[SitePublicHours];	
		
	    	echo "<td valign=top>\n";
		    if (!empty($sSiteName)) { echo "<b>$sSiteName</b><br>\n"; }
		    if (!empty($sStreet1)) { echo "$sStreet1<br>\n"; }
		    if (!empty($sStreet2)) { echo "$sStreet2<br>\n"; }
		 	echo "$sCity $sState $sZip<br>\n";
		 	
	        if (!empty($pURL)) {
				echo "<a href=\"http://".$pURL."\" target=\"_blank\" title=\"Visit $pURL\">$pURL</a><br>\n";			
			}
			if (!empty($sEmail)) {
	            echo "<a href=\"mailto:".$sEmail."\">$sEmail</a>\n";
			}
			echo "<p></p>\n";
			// Phone Numbers
			if (!empty($sPhone1)) { echo "Main: $sPhone1<br>\n"; }
			if (!empty($sPhone2)) { echo "Toll-Free: $sPhone2<br>\n"; }
			if (!empty($sPhone3)) { echo "Fax: $sPhone3<br>\n"; }
			if (!empty($sPhone4)) { echo "TTY: $sPhone4<br>\n"; }
			echo "</td><td valign=top>\n";
			// Additional Contacts
			if (!empty($sContact1) || !empty($sContact2)) {
			    // Check Contact #1
				$sqlC1 = "SELECT * from oa_btb_Contacts WHERE Contact_PID = '$sContact1'";
				$resultC1 = mysql_db_query($dbname,$sqlC1);
				$rowC1 = mysql_fetch_assoc($resultC1);
				$cName = $rowC1[GI_NamePrefix]." ".$rowC1[GI_NameFirst]." ".$rowC1[GI_NameLast]." ".$rowC1[GI_NameSuffix];
				
				echo "<b>$cName</b><br>\n";
				if (!empty($rowC1[GI_ProfessionalTitle])) { echo $rowC1[GI_ProfessionalTitle]."<br>\n"; }
				if (!empty($rowC1[CI_PhoneNumber])) { echo $rowC1[CI_PhoneNumber]."<br>\n"; }
				if (!empty($rowC1[CI_EmailAddress])) {
					echo "<a href=\"mailto:".$rowC1[CI_EmailAddress]."\" title=\"".$rowC1[CI_EmailAddress]."\">\n";
					echo $rowC1[CI_EmailAddress];
					echo "</a>\n";
				}
	
				// Check Contact #2
				if (!empty($sContact2)) {
					$sqlC2 = "SELECT * from oa_btb_Contacts WHERE Contact_PID = '$sContact2'";
					$resultC2 = mysql_db_query($dbname,$sqlC2);
					$rowC2 = mysql_fetch_assoc($resultC2);
					$cName = $rowC2[GI_NamePrefix]." ".$rowC2[GI_NameFirst]." ".$rowC2[GI_NameLast]." ".$rowC2[GI_NameSuffix];
	                echo "<b>$cName</b><br>\n";
					if (!empty($rowC1[GI_ProfessionalTitle])) { echo $rowC2[GI_ProfessionalTitle]."<br>\n"; }
					if (!empty($rowC2[CI_PhoneNumber])) { echo $rowC2[CI_PhoneNumber]."<br>\n"; }
					if (!empty($rowC2[CI_EmailAddress])) {
						echo "<a href=\"mailto:".$rowC2[CI_EmailAddress]."\">\n";
						echo $rowC2[CI_EmailAddress]."</a>\n";
					}
				}
			}
			echo "</td>\n";
			echo "</tr>\n";
		}	
		?>
		</table>
		
		<p></p>
	<? if ($rowsS > 0) { ?>
	<div class="crimson">Products &amp; Services</div>
	<div id="innerRightColWhite">
	<ul class="sidebar">
		<?
		while ($value = mysql_fetch_assoc($resultS)) {
		    $sID   = $value[Product_PID];
		    $sName = stripslashes($value[ProductNameFull]);
		    $sTypeID = $value[ProductType_ID];
		    
	  		echo "<li>\n";
			if (!empty($sTypeID) && ($sTypeID > 0)) {
				echo "<a href=\"results.php?search=1&product_PID=$sTypeID\" title=\"View All Service Providers for $sName\">";
			}
			echo $sName;
			if (!empty($sTypeID) && ($sTypeID > 0)) { echo "</a>"; }
			echo "\n";
			echo "</li>\n";
		}
		?>
	</ul>
	</div>
	<? } ?>
	<hr width="100%" color="#CCCCCC" size="1" noshade>
	<div class="crimson">Service Provider Description</div>
	    <?
	    if (!empty($pMission)) { echo "<b>Mission:</b> $pMission<br><br>\n"; }
		if (!empty($pDesc)) { echo $pDesc."<br><br>\n"; }		
	    ?>
	<hr width="100%" color="#CCCCCC" size="1" noshade>
	<div align="right">
		<b>www.OregonAbility.org : A service of OrPTI</b><br>
		1-888-505-2673 : info@OregonAbility.org
	</div>
</div>

</body>
</html>